using System.Collections;
using System.Collections.Generic;
using Cinemachine;
using MyFrame.Event;
using UnityEngine;

public class SwitchBounds : MonoBehaviour
{

    private void OnEnable()
    {
        EventCenter.Instance.On(EventEnum.AfterSceneLoad, SwitchConfinerShape);
    }
    private void OnDisable(){
        EventCenter.Instance.Off(EventEnum.AfterSceneLoad, SwitchConfinerShape);
    }

    private void SwitchConfinerShape()
    {
        PolygonCollider2D collider = GameObject.FindGameObjectWithTag("BoundsConfiner").GetComponent<PolygonCollider2D>();

        GetComponent<CinemachineConfiner>().m_BoundingShape2D = collider;

        //清除缓存   边界点在运行时改变，就要调用 
        GetComponent<CinemachineConfiner>().InvalidatePathCache();
    }
}
